﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Resources;
using System.Globalization;
using System.Text.RegularExpressions;


namespace atm_qlda
{
    public partial class frmDeposit : Form
    {
        CultureInfo culture;
        string language;
        string id;
        string errordeposit;
        string succ;
        SqlConnection conn;
        DataSet ds;
        DataTable dt;
        SqlDataAdapter da;
        
        
        public frmDeposit()
        {
            InitializeComponent();
            conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.AppSettings["conStr"];
            da = new SqlDataAdapter();
            conn.Open();
        }

        private void Deposit_Load(object sender, EventArgs e)
        {
            
            
        }

        public void chuyendl2(string dl,string lag)
        {
            this.id = dl;
            this.language = lag;
        }

        public bool CheckValue1()
        {
            bool check;
            String tien = txt_sotiengui.Text;
            int tiengui = Int32.Parse(tien);
            if (tiengui < 100000||tiengui>3000000)
             {
                 MessageBox.Show(errordeposit);
                 txt_sotiengui.Clear();
                 txt_sotiengui.Focus();
                check = false;
             }else
            {
                check = true;
            }
            return check;
         }
        

       

       

        //click_OK----------------------
        public delegate void delegateSend(string text, string language);
        
        private void bt_ok_Click(object sender, EventArgs e)
        {
            string sotien = txt_sotiengui.Text;
            int sotiengui = Int32.Parse(sotien);
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.AppSettings["conStr"];
            String sql="select *from UserAcc where IDCard= '" + id + "'";
            conn.Open();
            dt = new DataTable();
            ds = new DataSet();
            da = new SqlDataAdapter(sql,conn);
            da.Fill(ds, "UserAcc");
            dt = ds.Tables["UserAcc"];
            DataRow dr = dt.Rows[0];
            string count = dr["Balance"].ToString();
            int balance = Int32.Parse(count);

             
            if(CheckValue1()==true)

            {
                balance = balance + sotiengui;
                dr["Balance"] = balance;
                da.UpdateCommand = new SqlCommand("update UserAcc set Balance = '" + dr["Balance"] + "' where IDCard = '" + id + "'", conn);
                da.Update(ds, "UserAcc");
                chooseReport cr = new chooseReport();
                delegateSend dele = new delegateSend(cr.chuyendl3);
                dele(this.id, this.language);
                cr.Show();
                cr.SetLanguage(language);
                this.Hide();
            }
            conn.Close();
        
        }

        //clickz_Cancel------------------
        private void bt_cancel_Click(object sender, EventArgs e)
        {
            txt_sotiengui.Clear();
        }

        private void bt_exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txt_sotiengui_TextChanged(object sender, EventArgs e)
        {
            this.txt_sotiengui.Focus();
        }


        public void sendl(string id, string lag)
        {
            this.id = id;
            this.language = lag;
        }

        public void SetLanguage(string cultureName)
        {

            culture = CultureInfo.CreateSpecificCulture(cultureName);
            ResourceManager rm = new ResourceManager("atm_qlda.Lang.MyResource", typeof(frmDeposit).Assembly);
            label1.Text = rm.GetString("bank",culture);
            label2.Text = rm.GetString("titlegui", culture);
            label4.Text = rm.GetString("enter");
            label5.Text = rm.GetString("reset", culture);
            label6.Text = rm.GetString("bttout", culture);
            errordeposit = rm.GetString("errordeposit", culture);
            succ = rm.GetString("succ", culture);

        }

        private void bttClear_Click(object sender, EventArgs e)
        {
            txt_sotiengui.Clear();
            txt_sotiengui.Focus();
        }
    }
}
